<template>
  <div class="user">
    <!-- 头部导航 -->
    <div class="topmsg">
      <!-- 图片 -->
      <van-image round width="64" height="64" :src="userInfo.photo" />
      <p>
        {{ userInfo.name }}
        <br />
        <van-tag type="primary" plain size="medium">{{
          userInfo.birthday
        }}</van-tag>
      </p>
    </div>

    <!-- 用户操作 -->
    <van-row class="user-nav">
      <van-col span="8">
        <van-icon name="newspaper-o" color="#7af" />我的作品
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="#f00" />我的收藏
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="#fa0" />阅读历史
      </van-col>
    </van-row>

    <!-- 列表 -->
    <van-cell-group class="user-group">
      <van-cell
        icon="edit"
        title="编辑资料"
        is-link
        @click="$router.push({ path: '/edit' })"
      />
      <van-cell icon="chat-o" title="小智同学" is-link />
      <van-cell icon="setting-o" title="系统设置" is-link />
      <van-cell icon="warning-o" title="退出登录" is-link @click="unlogin" />
    </van-cell-group>
  </div>
</template>

<script>
import { removeToken } from '@/utils/token.js'
import { getUserInfo } from './user.js'
export default {
  name: 'user',
  data () {
    return { userInfo: {} }
  },
  methods: {
    unlogin () {
      console.log(removeToken())
      removeToken()
    }
  },
  created () {
    // 获取用户信息
    getUserInfo().then(res => {
      //   console.log(res)
      this.userInfo = res.data.data
    })
  }
}
</script>

<style lang="less">
.user {
  .topmsg {
    height: 100px;
    background-color: #0098fa;
    display: flex;
    align-items: center;
    .van-image {
      padding: 20px;
    }
    p {
      font-size: 16px;
      color: #fff;
    }
  }
  .van-col {
    justify-content: center;
    text-align: center;
    padding: 10px 0;
    font-size: 16px;
    .van-icon {
      display: block;
      font-size: 28px;
      margin-bottom: 10px;
    }
  }
}
</style>
